<?php

declare(strict_types=1);

namespace App\Controller;

use Exception;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Http\Message\ResponseInterface;
use Hyperf\HttpServer\Annotation\Middleware;
use App\Middleware\UserAuthorizationMiddleware;
use App\Middleware\UserPermissionMiddleware;
use App\Service\Logic\CustomModuleDataLogic;

/**
 * 自定义模块数据-控制器
 */
#[Controller(prefix: "/api/customModuleData")]
#[Middleware(UserAuthorizationMiddleware::class)]
#[Middleware(UserPermissionMiddleware::class)]
class CustomModuleDataController extends AbstractController
{
        #[Inject]
        protected CustomModuleDataLogic $logic;

        /**
         * 分页
         * @return ResponseInterface
         * @throws Exception
         */
        #[RequestMapping(path: "{customModuleId}", methods: "get")]
        public function paginate(): ResponseInterface
        {
                return $this->response->json($this->logic->paginate());
        }

        /**
         * 创建
         * @return ResponseInterface
         * @throws ContainerExceptionInterface
         * @throws NotFoundExceptionInterface
         * @throws Exception
         */
        #[RequestMapping(path: "{customModuleId}", methods: "post")]
        public function create(): ResponseInterface
        {
                return $this->response->json($this->logic->create());
        }

        /**
         * 更新
         * @return ResponseInterface
         * @throws ContainerExceptionInterface
         * @throws NotFoundExceptionInterface
         * @throws Exception
         */
        #[RequestMapping(path: "{customModuleId}", methods: "put")]
        public function update(): ResponseInterface
        {
                return $this->response->json($this->logic->update());
        }

        /**
         * 删除
         * @return ResponseInterface
         * @throws ContainerExceptionInterface
         * @throws NotFoundExceptionInterface
         */
        #[RequestMapping(path: "{customModuleId}", methods: "delete")]
        public function delete(): ResponseInterface
        {
                return $this->response->json($this->logic->delete());
        }
}